package com.zmm.weblog.admin.service.impl;

import com.zmm.weblog.admin.model.vo.dashboard.FindDashboardStatisticsInfoRspVo;
import com.zmm.weblog.admin.service.AdminDashboardService;
import com.zmm.weblog.common.domain.dos.ArticleDo;
import com.zmm.weblog.common.domain.mapper.ArticleMapper;
import com.zmm.weblog.common.domain.mapper.CategoryMapper;
import com.zmm.weblog.common.domain.mapper.TagMapper;
import com.zmm.weblog.common.utils.Response;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 福禄寿
 * @Date: 2024/9/2 下午2:24
 * @Des: weblog-springboot
 **/
@Service
public class AdminDashboardServiceImpl implements AdminDashboardService {

    @Autowired
    ArticleMapper articleMapper;
    @Autowired
    CategoryMapper categoryMapper;
    @Autowired
    TagMapper tagMapper;

    @Override
    public Response findDashboardStatistics() {

        Long articleTotalCount = articleMapper.selectCount(null);
        Long categoryTotalCount = categoryMapper.selectCount(null);
        Long tagTotalCount = tagMapper.selectCount(null);
        List<ArticleDo> articleDos = articleMapper.selectAllReadNum();
        Long pvTotalCount = 0L;
        if (!articleDos.isEmpty()) {
            pvTotalCount = articleDos.stream().mapToLong(ArticleDo::getReadNum).sum();
        }
        FindDashboardStatisticsInfoRspVo vo = FindDashboardStatisticsInfoRspVo.builder()
                .pvTotalCount(pvTotalCount)
                .articleTotalCount(articleTotalCount)
                .categoryTotalCount(categoryTotalCount)
                .tagTotalCount(tagTotalCount).build();
        return Response.success(vo);
    }
}
